package com.alks.common.utils.excelUtils;

import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder;
import org.apache.poi.ss.usermodel.Sheet;

/**
 * @author: chen
 * @date: 2024/11/29
 * @description: 冻结单元格
 */
public class FreezeTopRowsHandler implements SheetWriteHandler {

    private final int freezeCol;
    private final int freezeRow;

    public FreezeTopRowsHandler(int freezeCol, int freezeRow) {
        this.freezeCol = freezeCol;
        this.freezeRow = freezeRow;
    }

    @Override
    public void beforeSheetCreate(WriteWorkbookHolder workbook, WriteSheetHolder writeSheetHolder) {
    }

    @Override
    public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) {
        Sheet sheet = writeSheetHolder.getSheet();
        // 冻结窗口
        sheet.createFreezePane(freezeCol, freezeRow);
    }
}
